package com.gjy.sharding.jdbc.config;

import org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-07-10 10:37:00
 */
public class ShardingDsConfig {

    public DataSource shardingDataSource() {
        try {
            String databaseName = "";
            HashMap<String, DataSource> dataSourceMap = new HashMap<>();

            ArrayList<RuleConfiguration> ruleConfig = new ArrayList<>();


            Properties props = new Properties();
            props.put(ConfigurationPropertyKey.SQL_SHOW, true);
            return ShardingSphereDataSourceFactory.createDataSource(databaseName, dataSourceMap, ruleConfig, props);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

}
